package com.irdstudio.tdp.console.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.tdp.console.service.facade.OsrvInoutInfoService;
import com.irdstudio.tdp.console.dao.OsrvInoutInfoDao;
import com.irdstudio.tdp.console.dao.domain.OsrvInoutInfo;
import com.irdstudio.tdp.console.service.vo.OsrvInoutInfoVO;
import com.irdstudio.sdk.beans.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 外部模型输入输出				<p>
 * @author zjj
 * @date 2021-03-16
 */
@Service("osrvInoutInfoServiceImpl")
public class OsrvInoutInfoServiceImpl implements OsrvInoutInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(OsrvInoutInfoServiceImpl.class);

	@Autowired
	private OsrvInoutInfoDao osrvInoutInfoDao;
	
	/**
	 * 新增操作
	 */
	public int insertOsrvInoutInfo(OsrvInoutInfoVO inOsrvInoutInfoVo) {
		logger.debug("当前新增数据为:"+ inOsrvInoutInfoVo.toString());
		int num = 0;
		try {
			OsrvInoutInfo osrvInoutInfo = new OsrvInoutInfo();
			beanCopy(inOsrvInoutInfoVo, osrvInoutInfo);
			num = osrvInoutInfoDao.insertOsrvInoutInfo(osrvInoutInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(OsrvInoutInfoVO inOsrvInoutInfoVo) {
		logger.debug("当前删除数据条件为:"+ inOsrvInoutInfoVo);
		int num = 0;
		try {
			OsrvInoutInfo osrvInoutInfo = new OsrvInoutInfo();
			beanCopy(inOsrvInoutInfoVo, osrvInoutInfo);
			num = osrvInoutInfoDao.deleteByPk(osrvInoutInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inOsrvInoutInfoVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(OsrvInoutInfoVO inOsrvInoutInfoVo) {
		logger.debug("当前修改数据为:"+ inOsrvInoutInfoVo.toString());
		int num = 0;
		try {
			OsrvInoutInfo osrvInoutInfo = new OsrvInoutInfo();
			beanCopy(inOsrvInoutInfoVo, osrvInoutInfo);
			num = osrvInoutInfoDao.updateByPk(osrvInoutInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inOsrvInoutInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public OsrvInoutInfoVO queryByPk(OsrvInoutInfoVO inOsrvInoutInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inOsrvInoutInfoVo);
		try {
			OsrvInoutInfo queryOsrvInoutInfo = new OsrvInoutInfo();
			beanCopy(inOsrvInoutInfoVo, queryOsrvInoutInfo);
			OsrvInoutInfo queryRslOsrvInoutInfo = osrvInoutInfoDao.queryByPk(queryOsrvInoutInfo);
			if (Objects.nonNull(queryRslOsrvInoutInfo)) {
				OsrvInoutInfoVO outOsrvInoutInfoVo = beanCopy(queryRslOsrvInoutInfo, new OsrvInoutInfoVO());
				logger.debug("当前查询结果为:"+ outOsrvInoutInfoVo.toString());
				return outOsrvInoutInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<OsrvInoutInfoVO> queryAllOwner(OsrvInoutInfoVO osrvInoutInfoVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<OsrvInoutInfoVO> list = null;
		try {
			List<OsrvInoutInfo> osrvInoutInfos = osrvInoutInfoDao.queryAllOwnerByPage(osrvInoutInfoVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ osrvInoutInfos.size());
			pageSet(osrvInoutInfos, osrvInoutInfoVo);
			list = (List<OsrvInoutInfoVO>) beansCopy(osrvInoutInfos, OsrvInoutInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<OsrvInoutInfoVO> queryAllCurrOrg(OsrvInoutInfoVO osrvInoutInfoVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<OsrvInoutInfo> osrvInoutInfos = osrvInoutInfoDao.queryAllCurrOrgByPage(osrvInoutInfoVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+osrvInoutInfos.size());
		List<OsrvInoutInfoVO> list = null;
		try {
			pageSet(osrvInoutInfos, osrvInoutInfoVo);
			list = (List<OsrvInoutInfoVO>) beansCopy(osrvInoutInfos, OsrvInoutInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<OsrvInoutInfoVO> queryAllCurrDownOrg(OsrvInoutInfoVO osrvInoutInfoVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<OsrvInoutInfo> osrvInoutInfos = osrvInoutInfoDao.queryAllCurrDownOrgByPage(osrvInoutInfoVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ osrvInoutInfos.size());
		List<OsrvInoutInfoVO> list = null;
		try {
			pageSet(osrvInoutInfos, osrvInoutInfoVo);
			list = (List<OsrvInoutInfoVO>) beansCopy(osrvInoutInfos, OsrvInoutInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
